package com.sinven.controller.manage;

import com.sinven.common.ActionResult;
import com.sinven.pojo.Apply;
import com.sinven.service.ApplyService;
import com.sinven.util.ResultUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/manage")
@Slf4j
public class ApplyController {

    @Autowired
    private ApplyService applyService;

    @GetMapping("applies")
    public ActionResult<List<Apply>> queryApplies(@RequestParam(value = "curPage", defaultValue = "1") Integer curPage,
                                                  @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                                  Integer status){
        return applyService.queryCurPageData(curPage,pageSize,status);
    }

    @PutMapping("applies")
    public ActionResult updateApply(@RequestBody Apply apply) {
        log.debug(apply.toString());
        boolean result = applyService.updateApply(apply);
        if (result) {
            return ResultUtil.success();
        } else {
            return ResultUtil.error(500, "服务器错误");
        }
    }

    @DeleteMapping("applies/{id}")
    public ActionResult deleteApply(@PathVariable("id") long id){
        boolean result = applyService.deleteApply(id);
        if (result) {
            return ResultUtil.success();
        } else {
            return ResultUtil.error(500, "服务器错误");
        }
    }
}
